import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(title: const Text("Flutter App")),
        body: MyHomePage(),
      ),
    );
  }
}

//事件拦截应用
class MyHomePage extends StatelessWidget {
  _onPointerDown(PointerDownEvent event) {
    print("_onPointerDown：$event");
  }

  _onPointerMove(PointerMoveEvent event) {
    print("_onPointerMove：$event");
  }

  _onPointerUp(PointerUpEvent event) {
    print("_onPointerUp：$event");
  }

  _onPointerDown1(PointerDownEvent event) {
    print("_onPointerDown1：$event");
  }

  _onPointerMove1(PointerMoveEvent event) {
    print("_onPointerMove1：$event");
  }

  _onPointerUp1(PointerUpEvent event) {
    print("_onPointerUp1：$event");
  }

  @override
  Widget build(BuildContext context) {
    return Listener(
        onPointerDown: _onPointerDown,
        onPointerMove: _onPointerMove,
        onPointerUp: _onPointerUp,
        child: AbsorbPointer(
            //该值为false,则不拦截，默认为true
            absorbing: false,
            child: Listener(
              onPointerDown: _onPointerDown1,
              onPointerMove: _onPointerMove1,
              onPointerUp: _onPointerUp1,
              child: Container(
                color: Colors.red,
                width: 200.0,
                height: 100.0,
              ),
            )));
  }
}
